package bigdata.hourglass.engine.repl

import org.apache.spark.SparkConf
import org.json4s.JsonAST.JObject

/**
 * @author leo.jie (weixiao.me@aliyun.com)
 * @organization DataReal
 * @version 1.0
 * @website https://www.jlpyyf.com
 * @date 2019/12/8 8:09 下午
 * @since 1.0
 */
object Interpreter {

  abstract class ExecuteResponse

  case class ExecuteSuccess(content: JObject) extends ExecuteResponse

  case class ExecuteError(eName: String, eValue: String, traceBack: Seq[String] = Seq()) extends ExecuteResponse

  case class ExecuteIncomplete() extends ExecuteResponse

  case class ExecuteAborted(message: String) extends ExecuteResponse

}

trait Interpreter {

  import Interpreter._

  /**
   * start the Interpreter
   *
   * @return SparkConf
   */
  def start(): SparkConf

  /**
   * Execute the code and return the result, it may
   * take some time to execute.
   */
  protected[repl] def execute(code: String): ExecuteResponse

  /** Shut down the interpreter. */
  def close(): Unit
}
